<!DOCTYPE html>
<html lang="zh-CN" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>事件驱动系统 | Homalos</title>
    <meta name="description" content="基于 Python 的量化交易系统">
    <meta name="generator" content="VitePress v1.6.3">
    <link rel="preload stylesheet" href="/assets/style.RmNjDeKb.css" as="style">
    <link rel="preload stylesheet" href="/vp-icons.css" as="style">
    <script type="module" src="/assets/chunks/metadata.28daeedd.js"></script>
    <script type="module" src="/assets/app.BvKZi2Jp.js"></script>
    <link rel="preload" href="/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
    <link rel="modulepreload" href="/assets/chunks/framework.CXkkaYWf.js">
    <link rel="modulepreload" href="/assets/chunks/theme.C_3djJbO.js">
    <link rel="modulepreload" href="/assets/chunks/katex.ChWnQ-fc.js">
    <link rel="modulepreload" href="/assets/chunks/dagre-FFZHY6LT.v5YVXi2p.js">
    <link rel="modulepreload" href="/assets/chunks/c4Diagram-6F6E4RAY.nCOphmw6.js">
    <link rel="modulepreload" href="/assets/chunks/flowDiagram-PKI6S5ZS.CNud1oVM.js">
    <link rel="modulepreload" href="/assets/chunks/erDiagram-R3QVA2FD.DXgbj8um.js">
    <link rel="modulepreload" href="/assets/chunks/gitGraphDiagram-GW3U2K7C.BIFeTK-V.js">
    <link rel="modulepreload" href="/assets/chunks/ganttDiagram-EK5VF46D.DQ3Wppe5.js">
    <link rel="modulepreload" href="/assets/chunks/infoDiagram-XT3IWWJI.BaVwhgm7.js">
    <link rel="modulepreload" href="/assets/chunks/pieDiagram-NIOCPIFQ.DSbeskqj.js">
    <link rel="modulepreload" href="/assets/chunks/quadrantDiagram-2OG54O6I.DF4IDJMG.js">
    <link rel="modulepreload" href="/assets/chunks/xychartDiagram-H2YORKM3.CdWfFttn.js">
    <link rel="modulepreload" href="/assets/chunks/requirementDiagram-SO3GGRV7.DMU_G9xQ.js">
    <link rel="modulepreload" href="/assets/chunks/sequenceDiagram-ZIKVLSP4.kn4OakjH.js">
    <link rel="modulepreload" href="/assets/chunks/classDiagram-BGRH5UQR.DgQjJs6U.js">
    <link rel="modulepreload" href="/assets/chunks/classDiagram-v2-O24JOBDK.DgQjJs6U.js">
    <link rel="modulepreload" href="/assets/chunks/stateDiagram-XX37X6EN.CRy2e-oJ.js">
    <link rel="modulepreload" href="/assets/chunks/stateDiagram-v2-GD6S3NHB.BvRhId1O.js">
    <link rel="modulepreload" href="/assets/chunks/journeyDiagram-EWQZEKCU.BmQuVtJT.js">
    <link rel="modulepreload" href="/assets/chunks/timeline-definition-RI47OAVP.BxnQlAvf.js">
    <link rel="modulepreload" href="/assets/chunks/mindmap-definition-CZNETY7S.COCrfbvy.js">
    <link rel="modulepreload" href="/assets/chunks/kanban-definition-ILFWEQ3N.ChbXTd5M.js">
    <link rel="modulepreload" href="/assets/chunks/sankeyDiagram-4UZDY2LN.CpcNCvzD.js">
    <link rel="modulepreload" href="/assets/chunks/diagram-5UYTHUR4.J7RHmGCi.js">
    <link rel="modulepreload" href="/assets/chunks/diagram-ZTM2IBQH.BuJ-LU2f.js">
    <link rel="modulepreload" href="/assets/chunks/blockDiagram-PHRCVELO.DewF8s8X.js">
    <link rel="modulepreload" href="/assets/chunks/architectureDiagram-NQ2NVSRB.wzQlUmK0.js">
    <link rel="modulepreload" href="/assets/chunks/diagram-3EMPZRKU.1yGJgsvk.js">
    <link rel="modulepreload" href="/assets/chunks/virtual_mermaid-config.DDnGl6nM.js">
    <link rel="modulepreload" href="/assets/core_event_driven_system.md.CowBTyqS.lean.js">
    <link rel="icon" type="image/png" sizes="32x32" href="/assets/newnewlogo.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/assets/newnewlogo.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/assets/newnewlogo.png">
    <link rel="mask-icon" href="/assets/newnewlogo.png" color="#5bbad5">
    <meta name="theme-color" content="#5f67ee">
    <script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
    <script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--[--><!--]--><!--]--><!--[--><span tabindex="-1" data-v-0b0ada53></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0b0ada53>Skip to content</a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-1168a8e4><a class="title" href="/" data-v-1168a8e4><!--[--><!--]--><!--[--><img class="VPImage logo" src="/assets/newnewlogo.png" width="24" height="24" alt data-v-8426fc1a><!--]--><span data-v-1168a8e4>Homalos</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/guide/quick_start" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>快速开始</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/other/about" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>关于</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Homalos/Homalos" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-bd121fe5><span class="vpi-social-github"></span></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-cf11d7a2><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-cf11d7a2><span class="vpi-more-horizontal icon" data-v-cf11d7a2></span></button><div class="menu" data-v-cf11d7a2><div class="VPMenu" data-v-cf11d7a2 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>主题</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Homalos/Homalos" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-bd121fe5><span class="vpi-social-github"></span></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--[--><!--[--><div class="VPFlyout VPNolebaseEnhancedReadabilitiesMenu VPNolebaseEnhancedReadabilitiesMenuFlyout" aria-label="阅读增强" role="menuitem" data-v-cf11d7a2><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-cf11d7a2><span class="text" data-v-cf11d7a2><span class="i-icon-park-outline:book-open option-icon" data-v-cf11d7a2></span><!----><span class="vpi-chevron-down text-icon" data-v-cf11d7a2></span></span></button><div class="menu" data-v-cf11d7a2><div class="VPMenu" data-v-cf11d7a2 data-v-b98bc113><!----><!--[--><!--]--></div></div></div><!--]--><!--]--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>菜单</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-8a42e2b4><button data-v-8a42e2b4>回到顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b3fd67f8><div class="item" role="button" tabindex="0" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><h2 class="text" data-v-b3fd67f8>快速开始</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b3fd67f8><span class="vpi-chevron-right caret-icon" data-v-b3fd67f8></span></div></div><div class="items" data-v-b3fd67f8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/guide/quick_start" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>目录导航</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/guide/homalos" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>什么是 Homalos</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/guide/install" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>安装</p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" role="button" tabindex="0" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><h3 class="text" data-v-b3fd67f8>启动</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b3fd67f8><span class="vpi-chevron-right caret-icon" data-v-b3fd67f8></span></div></div><div class="items" data-v-b3fd67f8><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/guide/start/start_data_center" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>启动数据中心</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/guide/start/start_homalos" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>启动 Homalos</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" role="button" tabindex="0" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><h3 class="text" data-v-b3fd67f8>配置</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b3fd67f8><span class="vpi-chevron-right caret-icon" data-v-b3fd67f8></span></div></div><div class="items" data-v-b3fd67f8><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/guide/config/system_config" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>系统全局配置</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/guide/config/log_config" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>日志全局配置</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/guide/config/data_center_config" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>数据中心配置</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed has-active" data-v-c40bc020 data-v-b3fd67f8><div class="item" role="button" tabindex="0" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><h2 class="text" data-v-b3fd67f8>核心架构</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b3fd67f8><span class="vpi-chevron-right caret-icon" data-v-b3fd67f8></span></div></div><div class="items" data-v-b3fd67f8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/core/core" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>核心架构概述</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/core/event_driven_system" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>事件驱动系统</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/core/trading_engine" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>交易引擎</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/core/objects_and_service_registry" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>核心对象和服务注册表</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b3fd67f8><div class="item" role="button" tabindex="0" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><h2 class="text" data-v-b3fd67f8>网关和外部连接</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b3fd67f8><span class="vpi-chevron-right caret-icon" data-v-b3fd67f8></span></div></div><div class="items" data-v-b3fd67f8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/gateway/gateway" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>网关和外部连接概述</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/gateway/ctp_gateway" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>CTP网关</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/gateway/tts_gateway" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>TTS网关</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b3fd67f8><div class="item" role="button" tabindex="0" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><h2 class="text" data-v-b3fd67f8>数据中心</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b3fd67f8><span class="vpi-chevron-right caret-icon" data-v-b3fd67f8></span></div></div><div class="items" data-v-b3fd67f8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/datacenter/datacenter" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>数据中心概述</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b3fd67f8><div class="item" role="button" tabindex="0" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><h2 class="text" data-v-b3fd67f8>数据服务</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b3fd67f8><span class="vpi-chevron-right caret-icon" data-v-b3fd67f8></span></div></div><div class="items" data-v-b3fd67f8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/dataservice/dataservice" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>数据服务概述</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b3fd67f8><div class="item" role="button" tabindex="0" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><h2 class="text" data-v-b3fd67f8>系统面板</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b3fd67f8><span class="vpi-chevron-right caret-icon" data-v-b3fd67f8></span></div></div><div class="items" data-v-b3fd67f8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/dashboard/api" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>请求接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b3fd67f8><div class="item" role="button" tabindex="0" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><h2 class="text" data-v-b3fd67f8>其它</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b3fd67f8><span class="vpi-chevron-right caret-icon" data-v-b3fd67f8></span></div></div><div class="items" data-v-b3fd67f8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/other/community" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>社区资源</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/other/author" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>作者</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/other/about" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>联系</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>页面导航</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _core_event_driven_system" data-v-39a288b8><div><h1 id="事件驱动系统" tabindex="-1">事件驱动系统 <a class="header-anchor" href="#事件驱动系统" aria-label="Permalink to &quot;事件驱动系统&quot;">​</a></h1><div my-4 class="vp-nolebase-page-properties vp-nolebase-page-properties-container"><div class="vp-nolebase-page-properties-grid grid grid-cols-[180px_auto] gap-1 &lt;sm:grid-cols-[120px_auto]"><!--[--><!--[--><div transition="all ease-in-out" flex items-start text="zinc-400 dark:zinc-500 sm &lt;sm:xs" duration-250><div transition="all ease-in-out" min-h="8 &lt;sm:7" px="2 &lt;sm:1" py="2 &lt;sm:1" w-full flex cursor-pointer items-center bg="hover:zinc-100 dark:hover:zinc-800" rounded-md duration-250><div i-icon-park-outline:add-text mr-1></div><span overflow-hidden text-ellipsis whitespace-nowrap>字数</span></div></div><div cursor-pointer transition="all ease-in-out" min-h="8 &lt;sm:7" px="2 &lt;sm:1" py="1.5 &lt;sm:1" flex="~ row wrap" items-center gap-1 rounded-md text="sm &lt;sm:xs" bg="hover:zinc-100 dark:hover:zinc-800" duration-250><div class="vp-nolebase-page-property" data-page-property="value" data-page-property-type="dynamic" data-page-property-dynamic-type="word-count" w-full inline-flex items-center><span>809 字</span></div></div><!--]--><!--[--><div transition="all ease-in-out" flex items-start text="zinc-400 dark:zinc-500 sm &lt;sm:xs" duration-250><div transition="all ease-in-out" min-h="8 &lt;sm:7" px="2 &lt;sm:1" py="2 &lt;sm:1" w-full flex cursor-pointer items-center bg="hover:zinc-100 dark:hover:zinc-800" rounded-md duration-250><div i-icon-park-outline:timer mr-1></div><span overflow-hidden text-ellipsis whitespace-nowrap>阅读时间</span></div></div><div cursor-pointer transition="all ease-in-out" min-h="8 &lt;sm:7" px="2 &lt;sm:1" py="1.5 &lt;sm:1" flex="~ row wrap" items-center gap-1 rounded-md text="sm &lt;sm:xs" bg="hover:zinc-100 dark:hover:zinc-800" duration-250><div class="vp-nolebase-page-property" data-page-property="value" data-page-property-type="dynamic" data-page-property-dynamic-type="reading-time" w-full inline-flex items-center><span>4 分钟</span></div></div><!--]--><!--]--></div></div><h2 id="职责和范围" tabindex="-1">职责和范围 <a class="header-anchor" href="#职责和范围" aria-label="Permalink to &quot;职责和范围&quot;">​</a></h2><p>事件驱动系统是 Homalos 量化交易系统中所有组件之间实现异步、松耦合交互的基础通信机制。该系统以<code>EventBus</code>提供高性能事件路由的类为核心，具备双通道处理（同步和异步）、基于优先级的事件处理以及全面的线程安全。</p><p>本文档涵盖了<code>EventBus</code>事件系统的实现、事件类型和优先级、线程安全机制以及组件在整个系统中的异步通信方式。有关使用此事件系统的更广泛的系统架构的信息，请参阅<a class="VPNolebaseInlinePreviewLink" relative href="https://deepwiki.com/Homalos/Homalos/2-core-architecture" target="_blank" rel="noreferrer" data-v-7fde401a><!--[-->核心架构<!--]--><!----></a>。有关使用事件的特定组件的详细信息，请参阅<a class="VPNolebaseInlinePreviewLink" relative href="./trading_engine" data-v-7fde401a><!--[-->交易引擎<!--]--><!----></a>。</p><h2 id="eventbus-架构" tabindex="-1">EventBus 架构 <a class="header-anchor" href="#eventbus-架构" aria-label="Permalink to &quot;EventBus 架构&quot;">​</a></h2><p>该<code>EventBus</code>实现了双通道事件处理系统，具有单独的同步和异步队列，每个队列由专用的工作线程进行管理。</p><p>维护<code>EventBus</code>两个独立的处理通道：</p><table tabindex="0"><thead><tr><th>渠道</th><th>队列大小</th><th>线程</th><th>目的</th></tr></thead><tbody><tr><td>同步</td><td>10,000</td><td><code>_sync_thread</code></td><td>需要立即处理的时间关键事件</td></tr><tr><td>异步</td><td>10,000</td><td><code>_async_thread</code></td><td>后台处理和日志记录</td></tr></tbody></table><h2 id="事件类型和优先级" tabindex="-1">事件类型和优先级 <a class="header-anchor" href="#事件类型和优先级" aria-label="Permalink to &quot;事件类型和优先级&quot;">​</a></h2><p>事件系统使用全面的类型层次结构，并通过<code>EventPriority</code>枚举和<code>EventType</code>类实现基于优先级的处理。</p><p>优先级系统将事件路由到适当的处理通道：</p><table tabindex="0"><thead><tr><th>优先级</th><th>值</th><th>通道</th><th>示例事件</th></tr></thead><tbody><tr><td><code>CRITICAL</code></td><td>0</td><td>同步</td><td><code>SYSTEM_ERROR</code>，<code>RISK_REJECTED</code></td></tr><tr><td><code>HIGH</code></td><td>1</td><td>同步</td><td><code>ORDER</code>，<code>TRADE</code>, <code>GATEWAY_CONNECTED</code></td></tr><tr><td><code>NORMAL</code></td><td>2</td><td>异步</td><td><code>MARKET_TICK</code>，<code>POSITION_UPDATED</code></td></tr><tr><td><code>LOW</code></td><td>3</td><td>异步</td><td><code>LOG_MESSAGE</code>，<code>STATISTICS</code></td></tr></tbody></table><h2 id="线程安全和性能" tabindex="-1">线程安全和性能 <a class="header-anchor" href="#线程安全和性能" aria-label="Permalink to &quot;线程安全和性能&quot;">​</a></h2><p>系统通过<code>ThreadSafeCallback</code>类和内部的线程队列管理实现了全面的线程安全<code>EventBus</code>。</p><p>关键线程安全特性：</p><ul><li><strong>回调调度</strong>：<code>ThreadSafeCallback.schedule_async_task()</code>方法<code>schedule_callback()</code>处理跨线程通信</li><li><strong>重试逻辑</strong>：内置可配置的重试<code>max_retries</code>机制<code>retry_delay</code></li><li><strong>优雅关闭</strong>：<code>EventType.SHUTDOWN</code>基于超时的线程连接信号</li><li><strong>队列保护</strong>：<code>Queue.put_nowait()</code>通过<code>Full</code>异常处理来防止阻塞</li></ul><h2 id="事件流和通信" tabindex="-1">事件流和通信 <a class="header-anchor" href="#事件流和通信" aria-label="Permalink to &quot;事件流和通信&quot;">​</a></h2><p>事件驱动的通信模式通过标准化的事件发布和订阅实现系统组件之间的松耦合交互。</p><h2 id="使用模式" tabindex="-1">使用模式 <a class="header-anchor" href="#使用模式" aria-label="Permalink to &quot;使用模式&quot;">​</a></h2><h3 id="事件发布" tabindex="-1">事件发布 <a class="header-anchor" href="#事件发布" aria-label="Permalink to &quot;事件发布&quot;">​</a></h3><p>组件使用<code>EventBus.publish()</code>可选异步处理的方法发布事件：</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># High priority synchronous event</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event_bus.publish(Event(EventType.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">ORDER</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, order_data))</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Background asynchronous event  </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event_bus.publish(Event(EventType.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">MARKET_TICK</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, tick_data), </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">is_async</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Using convenience functions</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> create_trading_event(EventType.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">RISK_CHECK</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, risk_data)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event_bus.publish(event)</span></span></code></pre></div><h3 id="事件订阅" tabindex="-1">事件订阅 <a class="header-anchor" href="#事件订阅" aria-label="Permalink to &quot;事件订阅&quot;">​</a></h3><p>组件订阅特定的事件类型或使用全局处理程序：</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Subscribe to specific event type</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event_bus.subscribe(EventType.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">ORDER</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.handle_order)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Subscribe to async processing</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event_bus.subscribe(EventType.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">MARKET_TICK</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.handle_tick, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">is_async</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Global handler for all events</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event_bus.subscribe_global(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.handle_all_events)</span></span></code></pre></div><h3 id="事件监控" tabindex="-1">事件监控 <a class="header-anchor" href="#事件监控" aria-label="Permalink to &quot;事件监控&quot;">​</a></h3><p>系统通过事件监视器和统计数据提供全面的监控：</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Add event monitor</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event_bus.add_monitor(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.log_event)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Get runtime statistics</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">stats </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> event_bus.get_stats()</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Returns: total_events_published, sync_events_processed, </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#          async_events_processed, error_count, etc.</span></span></code></pre></div><p>事件驱动系统构成了 Homalos 架构的支柱，实现了所有系统组件之间的高性能、线程安全通信，同时保持了明确的关注点分离，并支持实时和后台处理要求。</p><!--[--><!----><div class="bg-$vp-custom-block-details-bg mt-6 vp-nolebase-git-changelog vp-nolebase-git-changelog-history vp-nolebase-git-changelog-history-list vp-nolebase-git-changelog-history-container" rounded-lg p-4 data-v-9cc63e9c><label cursor-pointer data-v-9cc63e9c><div class="vp-nolebase-git-changelog-title flex select-none items-center justify-between" transition="color ease-in-out" text="&lt;sm:xs" duration-200 data-v-9cc63e9c><span class="vp-nolebase-git-changelog-last-edited-title inline-flex items-center gap-3" data-v-9cc63e9c><div class="i-octicon:history-16" data-v-9cc63e9c></div><span data-v-9cc63e9c>最后编辑于 13 天前</span></span><div class="i-octicon:sort-desc-16" ml-auto mr-4 cursor-pointer data-v-9cc63e9c></div><span class="vp-nolebase-git-changelog-view-full-history-title inline-flex cursor-pointer items-center gap-3" data-v-9cc63e9c><span class="&lt;sm:hidden" data-v-9cc63e9c>查看完整历史</span><svg class="rotate-0 i-octicon:chevron-down-16" transition="transform ease-in-out" duration-200 data-v-9cc63e9c></svg></span></div></label><div style="display:none;" class="grid grid-cols-[30px_auto] mt-3 gap-1.5 children:my-auto -ml-1.5" text="&lt;sm:xs" data-v-9cc63e9c><!--[--><!--[--><!--[--><div class="i-octicon:git-commit-16 m-auto rotate-90 transform op-30" data-v-0e4a2b5f></div><div flex gap-1 align-baseline data-v-0e4a2b5f><a href="https://github.com/Homalos/HomalosDocs/commit/4384d966ea490bb4a72873dc5ec825566566b7a9" target="_blank" class="no-icon" data-v-0e4a2b5f><code class="text-xs text-$vp-c-brand-1 hover:text-$vp-c-brand-1" transition="color ease-in-out" duration-200 data-v-0e4a2b5f>4384d96</code></a><span data-v-0e4a2b5f>-</span><span data-v-0e4a2b5f><span class="text-sm &lt;sm:text-xs" data-v-0e4a2b5f>Update zh.ts、footerDta.ts and markdown files</span><span class="my-1 ml-3 gap-1" data-v-0e4a2b5f><!--[--><!--[--><img src="https://gravatar.com/avatar/b8d5677fa18909432d3b381a59fa6cbe31323f9c976d2c30c3d3c57032d01194?d=retro" alt="The avatar of contributor named as Donny" class="vp-nolebase-git-changelog-commit-avatar inline-block h-6 w-6 rounded-full v-middle" data-v-0e4a2b5f><!--]--><!--]--></span><!----></span></div><!--]--><!--]--><!--[--><!--[--><div class="i-octicon:git-commit-16 m-auto rotate-90 transform op-30" data-v-0e4a2b5f></div><div flex gap-1 align-baseline data-v-0e4a2b5f><a href="https://github.com/Homalos/HomalosDocs/commit/e3ee45802d234a11cded59e6ae8d2246549ae7f3" target="_blank" class="no-icon" data-v-0e4a2b5f><code class="text-xs text-$vp-c-brand-1 hover:text-$vp-c-brand-1" transition="color ease-in-out" duration-200 data-v-0e4a2b5f>e3ee458</code></a><span data-v-0e4a2b5f>-</span><span data-v-0e4a2b5f><span class="text-sm &lt;sm:text-xs" data-v-0e4a2b5f>Update gateway</span><span class="my-1 ml-3 gap-1" data-v-0e4a2b5f><!--[--><!--[--><img src="https://gravatar.com/avatar/b8d5677fa18909432d3b381a59fa6cbe31323f9c976d2c30c3d3c57032d01194?d=retro" alt="The avatar of contributor named as Donny" class="vp-nolebase-git-changelog-commit-avatar inline-block h-6 w-6 rounded-full v-middle" data-v-0e4a2b5f><!--]--><!--]--></span><!----></span></div><!--]--><!--]--><!--[--><!--[--><div class="i-octicon:git-commit-16 m-auto rotate-90 transform op-30" data-v-0e4a2b5f></div><div flex gap-1 align-baseline data-v-0e4a2b5f><a href="https://github.com/Homalos/HomalosDocs/commit/2a5dd9517432ae44dc52c9fab0062096f12c886e" target="_blank" class="no-icon" data-v-0e4a2b5f><code class="text-xs text-$vp-c-brand-1 hover:text-$vp-c-brand-1" transition="color ease-in-out" duration-200 data-v-0e4a2b5f>2a5dd95</code></a><span data-v-0e4a2b5f>-</span><span data-v-0e4a2b5f><span class="text-sm &lt;sm:text-xs" data-v-0e4a2b5f>Update zh.tx</span><span class="my-1 ml-3 gap-1" data-v-0e4a2b5f><!--[--><!--[--><img src="https://gravatar.com/avatar/b8d5677fa18909432d3b381a59fa6cbe31323f9c976d2c30c3d3c57032d01194?d=retro" alt="The avatar of contributor named as Donny" class="vp-nolebase-git-changelog-commit-avatar inline-block h-6 w-6 rounded-full v-middle" data-v-0e4a2b5f><!--]--><!--]--></span><!----></span></div><!--]--><!--]--><!--]--></div></div><!--]--></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><div class="edit-link" data-v-e257564d><a class="VPLink link vp-external-link-icon no-icon edit-link-button" href="https://github.com/Homalos/HomalosDocs/edit/main/src/core/event_driven_system.md" target="_blank" rel="noreferrer" data-v-e257564d><!--[--><span class="vpi-square-pen edit-link-icon" data-v-e257564d></span> 在 GitHub 上编辑此页面<!--]--></a></div><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>最后更新于: <time datetime="2025-07-18T15:23:16.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/core/core" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一页</span><span class="title" data-v-e257564d>核心架构概述</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/core/trading_engine" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一页</span><span class="title" data-v-e257564d>交易引擎</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!----><!--]--></div></div>
    
    
  </body>
</html>